<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>
			<%= title %>
		</title>
		<%- include('../include/stylelist') %>
		<%- include('../include/scriptlist') %>
	</head>

	<body class="layui-layout-body">
		<div class="layui-layout layui-layout-admin">
			<%- include('../include/head',{title:'woyao.tv'})  %>
			<%- include('../include/left',{title:'woyao.tv'})  %>

			<div class="layui-body">
				<!-- 内容主体区域 -->
				<div style="padding: 15px;">
					<table class="layui-table" lay-data="{url:'/admin/api/index/info',method:'post', page:true, id:'idTest',limit:'10'}" lay-filter="demo">
						<thead>
							<tr>
								<th lay-data="{type:'checkbox', fixed: 'left'}"></th>
								<th lay-data="{field:'Sub_id', width:130}">ID</th>
								<th lay-data="{field:'User_id', width:100}">用户ID</th>
								<th lay-data="{field:'Name', width:100}">用户名</th>
								<th lay-data="{field:'Content', width:130}">投稿内容</th>
								<th lay-data="{field:'ContentType', width:120,templet:'#ContentTypeTpl'}">投稿类型</th>
								<th lay-data="{field:'ContentAnnex', width:100}">附带内容</th>
								<th lay-data="{field:'SubCent', width:100, sort: true}">内容评论</th>
								<th lay-data="{field:'SubColle', width:100, sort: true}">内容收藏</th>
								<th lay-data="{field:'UpNumber', width:100, sort: true}">内容点赞</th>
								<th lay-data="{field:'BuryNumber', width:100, sort: true}">被讨厌</th>
								<th lay-data="{field:'SubTime', width:130,templet:'#SubTimeTpl', sort: true}">投稿时间</th>
								<th lay-data="{field:'Status',edit: 'text',width:100,templet:'#StatusTpl', sort: true}">审核状态</th>
								<th lay-data="{fixed: 'right', width:210, align:'center', toolbar: '#barDemo'}"></th>
							</tr>
						</thead>
					</table>

					<script type="text/html" id="barDemo">
						<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
						<a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
						<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="filter">未通过</a>
						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
					</script>

					<!-- 投稿类型 -->
					<script type="text/html" id="ContentTypeTpl">
						{{# if(d.ContentType == '3'){ }} 文本+视频 {{# } else if(d.ContentType == '2') { }} 文本+图片 {{# }else if(d.ContentType == '1') { }} 纯文本 {{# } }}
					</script>

					<!-- 投稿时间 -->
					<script type="text/html" id="SubTimeTpl">
						{{d.SubTime = d.SubTime.replace(/T/,' ').replace('.000Z','')}}
					</script>

					<!-- 审核状态 -->
					<script type="text/html" id="StatusTpl">
						{{# if(d.Status == '2'){ }} 通过 {{# } else if(d.Status == '0') { }} 未审核 {{# }else if(d.Status == '1') { }} 未通过 {{# } }}
					</script>
				</div>
			</div>

			<div class="layui-footer">
				<!-- 底部固定区域 -->
				© WoYao.Tv - 底部固定区域
			</div>
		</div>
		<script>
			//JavaScript代码区域
			layui.use('element', function() {
				var element = layui.element;
			});
			layui.use('table', function() {
				var table = layui.table;
				//监听表格复选框选择
				table.on('checkbox(demo)', function(obj) {
					console.log(obj)
				});
				//监听工具条
				table.on('tool(demo)', function(obj) {
					var laydata = obj.data;
					if(obj.event === 'detail') {
						layer.msg('ID：' + laydata.Sub_id + ' 的查看操作');
					} else if(obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							$.ajax({
								type: "post",
								url: "/admin/api/index/del",
								async: true,
								data: {
									"id": laydata.Sub_id
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('删除成功')
										obj.del();
										layer.close(index);
									} else {
										layer.msg(data.msg)
									}
								}
							});
						});
					} else if(obj.event === 'pass') {
						$.ajax({
							type: "post",
							url: "/admin/api/index/pass",
							async: true,
							data: {
								"id": laydata.Sub_id
							},
							success: function(data) {
								if(data.code == 0) {
									layer.msg('审核通过')
									obj.update({
										Status: 2
									});
								} else {
									layer.msg(data.msg)
								}
							}
						});
					} else if(obj.event === 'filter') {
						$.ajax({
							type: "post",
							url: "/admin/api/index/filter",
							async: true,
							data: {
								"id": laydata.Sub_id
							},
							success: function(data) {
								if(data.code == 0) {
									layer.msg('审核未通过')
									obj.update({
										Status: 1
									});
								} else {
									layer.msg(data.msg)
								}
							}
						});
					}
				});
				//监听单元格编辑

				var $ = layui.$,
					active = {
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('idTest'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('idTest');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.demoTable .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
			});
		</script>
	</body>

</html>